home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
natcomp.zip
/
COMPILE.CB
next >
Wrap
Text File
|
1990-03-14
|
16KB
|
561 lines
/*
* BRIEF -- Basic Reconfigurable Interactive Editing Facility
*
* Written by Dave Nanian and Michael Strickman.
*
* 1-14-90 Nat added code to translate environment variables
* which may be passed in on compile command line
*/
/*
* compile.cb:
*
* This file contains all of the standard BRIEF macros for compiling files.
*/
string trans_envar (string cmdln); // NAT - translates out env var's
string add_to_path (string path, string name);
string escape_re (string original, ~string);
int next_error (~int action);
int cc (string pass_string, ~string legal_extension, ~int check_warnings, ~int background, ~int continuation);
void _cc_complete (int ret_code, string full_name, int check_warnings, string pass_string);
int cm (...);
int cb (...);
extern int _check_warnings, // Check for warnings in the compiler output?
_background; // Run the compiler in the background?
/*
* compile_it:
*
* This function automatically compiles the file in the current
* buffer. It uses the "BC<extension>" environment variable to
* determine what to do with any given file. If no "BC<extension>"
* environment variable exists for the specific file extension being
* compiled, compile_it checks to see if it's ".c", ".m" or ".asm". If
* it's a macro file the "cm" macro is executed; if it's a C file, a
* generic "cc" command is used, and if it's an ASM file, the Macro
* Assembler is invoked.
*
* Other compilers can be supported very easily. Simply set a
* "BC<extension>" environment variable to the "pass string" you
* want to use. For example, if you wanted to call the (fictitious)
* UnderWare C compiler, which has two passes called "under" and "ware",
* you'd use the command:
*
* set bcc="under %s;ware %s"
*
* You must place the pass string in quotes. If you don't, compile_it
* calls a macro named whatever is in the pass string. So, for example,
* if you accidently set your pass string using the command:
*
* set bcc=under %s;ware %s
*
* compile_it would call a macro named "under %s;ware %s". This probably
* isn't what you want -- but this feature can be useful if you want to
* run some sort of custom macro for the file extension (compile_it does
* this when compiling cm files).
*
* Also note that DOS requires you to double any % characters that
* appear in a batch file. So if you were setting the BCC variable in
* your autoexec, you would use the line:
*
* set bcc="under %%s;ware %%s"
*
* Each pass begins with the name of the executable program that does
* that compilation pass. That is followed by the a space, the special
* string "%s", which is replaced by the filename (with NO extension),
* and the multiple pass separation character ";". If you want to put
* a ";" in your pass string, use "\;".
*
* These special characters are very important -- don't forget them!
* Remember that the special "%s" string is only replaced by the filename,
* not the filename and the extension. Up to seven of these can be specified
* in any given pass. If your compiler requires the extension as well,
* place it after this string (e.g. "cc -c %s.c").
*
* If you want to pass options to your compiler, you can place them
* either before or after the "%s". Placing them before puts the option
* before the filename, and vice versa.
*
* If your compiler doesn't return an error code, put an exclamation
* point in front of the first pass string (either inside or outside the
* quotes); this will override the current warnings_only setting and
* automatically check for errors in the compiler output.
*/
int compile_it (void)
{
string extension, // File extension of the current file.
command; // Command to be used to compile file.
inq_names (NULL, extension);
command = trans_envar( inq_environment( "BC" + upper (extension) ) );
if( !get_parm( 0, command, "Compile with: ", 80, command ) )
return( 0 );
if (command != "")
{
if (index (command, "\""))
{
int loc,
background;
background = _background;
while (loc = index (command, "\""))
command = substr (command, 1, loc - 1) + substr (command, loc + 1);
if (substr (command, strlen (command), 1) == "&")
{
background = 1;
command = trim (substr (command, 1, strlen (command) - 1));
}
if ("!" == substr (command, 1, 1))
returns (cc (substr (command, 2), extension, 1, background));
else
returns (cc (command, extension, NULL, background));
}
else
{
int check_warnings = _check_warnings;
if (substr (command, 1, 1) == "!")
{
check_warnings = 1;
command = substr (command, 2);
}
returns (execute_macro (command, command, check_warnings));
}
}
else
switch (extension)
{
case "m":
returns (cm (_check_warnings));
case "asm":
returns (cc ("masm %s\\;", extension));
case "c":
returns (cc ("cc -c %s.c", extension));
case "cb":
returns (cb (_check_warnings));
default:
{
error ("Can't compile: no BC%s environment variable.", upper (extension));
returns (-1);
}
}
}
/*
* warnings_only:
*
* This macro toggles whether or not errors are searched for when a
* compile is done and the compiler returns "no errors". Note that its
* value is saved in the state file.
*/
int warnings_only (~int)
{
int ret_code,
previous_value;
previous_value = _check_warnings;
if (!(ret_code = get_parm (0, _check_warnings)))
_check_warnings = !_check_warnings;
if (!ret_code || inq_called () == "")
message ("Compile warning detection %s.", _check_warnings ? "on" : "off");
returns (previous_value);
}
/*
* bgd_compilation:
*
* This macro toggles whether or not compilation is done in the
* background under operating systems that support it. Note that this
* value is saved in the state file.
*/
int bgd_compilation (~int)
{
int ret_code,
previous_value;
previous_value = _background;
if (!(ret_code = get_parm (0, _background)))
_background = !_background;
if (!ret_code || inq_called () == "")
message ("Background compilation %s.", _background ? "on" : "off");
returns (previous_value);
}
/*
* cc:
*
* This routine compiles the file in the current buffer using the
* passed "pass string" and the BRIEF DOS command. It needs a lot
* of memory to run -- either turn swapping on or start with at least
* 256K and -M20. Of course, this may vary depending with the size
* and memory requirements of the specific compiler you're using.
*
* The "pass string" passed should be of the form:
*
* pass_1 %s;pass_2 %s;...pass_n %s
*
* The optional second parameter is an extended file type -- this is
* used by the "cm" and "cb" macros, and to compile other types of files
* (e.g. .asm).
*
* If no pass string is specified, it defaults to a generic "cc"
* command. If no extension is specified, it defaults to "c".
*/
int cc (string pass_string, ~string legal_extension, ~int, ~int, ~int continuation)
{
string file_name, // The name of the file we're compiling.
path, // The path of the file we're compiling.
extension, // The extension of the file we're compiling.
command_line, // The compile command line.
old_path, // The original path we were on.
error_file; // The file to put error information in.
int loc, // Generic index place holder.
length, // Generic length place holder.
ret_code = 1, // Return code from DOS.
buffer_id, // Buffer ID of error buffer.
check_warnings, // Examine result of compile for errors?
background; // Do compilation in background?
/*
* We get the name of the file from inq_names and check to see
* if it's a legal extension.
*/
if (legal_extension == "")
legal_extension = "c";
inq_names (path, extension, file_name);
if (extension != legal_extension)
error ("Current buffer is not a .%s file.", pass_string);
else
{
/*